<template>
  <div class="service-order">
    <tags :labels="labels" :current-label="currentLabel" @clickLabel="clickLabel" class="tag">
      <ul class="list">
        <li
          v-for="(item, index) in list"
          :key="index"
          class="list-item border-bottom-1px"
        >
          <div class="time">
            <span class="text">接收时间:</span>
            <span class="value">{{ item.create_time }}</span>
          </div>
          <div class="pic">
            <div class="image" v-if="item.task && item.task.image">
              <img v-lazy="item.task.image.thumbnail_path" />
            </div>
          </div>
          <div class="title" v-if="item.task">
            {{ item.task.title }}
          </div>
          <div class="status">
            <div v-if="+item.status === 1">
              <cube-button inline primary @click="$router.push(`/service/task-upload/${item.id}`)">上传凭证</cube-button>
            </div>
            <div v-if="+item.status === 2">
              <span style="margin-right: 10px">审核中</span>
              <cube-button inline primary @click="$router.push(`/service/task-upload/${item.id}`)">查看</cube-button>
            </div>
            <div v-if="+item.status === 3">奖励: <span>{{ +item.commission }}</span></div>
            <div v-if="+item.status === 4">原因: <span>{{ item.reject }}</span></div>
          </div>
        </li>
      </ul>
      <pull-up
        :loading="loading"
        :busy="queryList.busy"
        @loadMore="loadMore" />
    </tags>
    <loading :show="loading" />
  </div>
</template>

<script>
import Tags from '../components/Tags'
import Loading from '@/components/Loading'
import api from '@/api'
import base64 from '@/util/base64'
import PullUp from '@/components/PullUp'
export default {
  name: 'TaskOder',
  components: {
    Tags,
    Loading,
    PullUp
  },
  filters: {
  },
  computed: {
    currentLabel() {
      return this.labels[this.current]
    }
  },
  data() {
    return {
      labels: [],
      current: 0,
      list: [],
      loading: false,
      queryList: {}
    }
  },
  methods: {
    loadMore() {
      setTimeout(() => {
        this.getList(true)
      }, 200)
    },
    getList(append = false) {
      if (this.queryList.busy === false) {
        this.queryList.page++
        this.loading = true
        this.queryList.busy = true
        api.Task.getOrderList({
          ...this.queryList,
          status: this.current
        }).then(response => {
          let { data } = response
          data = base64.parse(data)
          if (data.list.length === 0) {
            this.queryList.busy = true
          } else {
            this.queryList.busy = false
            if (append) {
              this.list = this.list.concat(data.list)
            } else {
              this.list = data.list
            }
          }
        }).finally(() => {
          this.loading = false
          console.log(this.list)
        })
      }
    },
    createTags () {
      const tags = []
      tags[0] = '全部'
      tags[1] = '待完成'
      tags[2] = '审核中'
      tags[3] = '已完成'
      tags[4] = '已驳回'
      this.labels = tags
    },
    clickLabel(index) {
      this.current = index
      this.init()
      this.list = []
      this.getList()
    },
    init() {
      this.queryList = this.queryList = {
        page: 0,
        pageSize: 10,
        busy: false
      }
    }
  },
  created () {
    this.current = Number.parseInt(this.$route.params.type || 0)
    this.createTags()
    this.init()
    this.getList()
  },
  deactivated () {
    this.queryList.busy = true
  }
}
</script>

<style scoped lang="stylus">
.service-order
  background white
  padding-bottom 30px
  border-radius 10px
  .list
    padding-bottom 15px
    .list-item
      padding 10px 0
      text-align left
      .time
        margin 10px 0
        .value
          margin-left 5px
      .pic
        display flex
        .image
          width 100px
          margin 10px 0
      .title
        height 35px
      .status
        padding-bottom 10px
        font-size 16px
        span
          color red

</style>
